package cn.flying.cloud.system.view;

import javax.annotation.Resource;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.flying.cloud.system.common.service.CodeService;
import cn.flying.cloud.system.tenant.entity.SysTenantInfo;
import cn.flying.cloud.system.tenant.service.SysTenantInfoService;


/**
 * 租户信息表 前端控制器
 *
 * @author: admin
 * @date: 2024-06-13 13:15:43
 * @version: 1.0
 */
@Controller
@RequestMapping("/sys/tenant/")
public class SysTenantViewController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private SysTenantInfoService sysTenantInfoService;
    @Resource
    private CodeService codeService;

    /**
     * 跳转到列表页面
     *
     * @return
     */
    @RequestMapping("index")
    public String list(Model model) {
        Map<String, String> statusList = codeService.getCodeList("status");
        model.addAttribute("statusList", statusList);
        return "sys/tenant/index";
    }

    /**
     * 新增/修改页面
     *
     * @param id
     * @param model
     * @return
     */
    @RequestMapping("turn/edit")
    public String turnEdit(Long id, Model model) {
        if (null != id) {
            SysTenantInfo tenantInfo = sysTenantInfoService.getById(id);
            model.addAttribute("tenant", tenantInfo);
        } else {
            SysTenantInfo tenantInfo = new SysTenantInfo();
            tenantInfo.setStatus("Y");
            model.addAttribute("tenant", tenantInfo);
        }
        return "sys/tenant/edit";
    }

}
